package com.tssm.action.usercenter;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.opensymphony.xwork2.ActionSupport;
import com.tssm.cache.memcached.TsSessionUtil;
import com.tssm.core.util.Pages;
import com.tssm.pojo.SarcRefer;
import com.tssm.pojo.SarcSupplier;
import com.tssm.service.SarcReferService;

@Controller("sarcReferAction")
@Scope("prototype")
public class SarcReferAction extends ActionSupport {
	
	@Resource
	private SarcReferService sarcReferService;
	private SarcSupplier ssup;
	private List<SarcRefer> srlist;
	private Long id;
	private Pages pages;
	private int currentPage;
	private int index;
	
	public String queryRefer() {
		HttpServletRequest request = ServletActionContext.getRequest();
		ssup = TsSessionUtil.getTsUser(request);
		pages = new Pages();
		pages.setAllNum(sarcReferService.queryReferCountById(ssup.getSupplierid()));
		if(currentPage == 0) currentPage = 1;
		pages.setCurrentPage(currentPage);
		int pageSize = 10;
		pages.setPageSize(pageSize);
		int pageCount = pages.getPageCount();
		pages.setPageCount(pageCount);//总页数		
		int firstIndex = (currentPage - 1) * pageSize;
		srlist = sarcReferService.queryReferById(ssup.getSupplierid(), firstIndex, pageSize);
		return "success";
	}

	public SarcReferService getSarcReferService() {
		return sarcReferService;
	}

	public void setSarcReferService(SarcReferService sarcReferService) {
		this.sarcReferService = sarcReferService;
	}

	public List<SarcRefer> getSrlist() {
		return srlist;
	}

	public void setSrlist(List<SarcRefer> srlist) {
		this.srlist = srlist;
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public Pages getPages() {
		return pages;
	}

	public void setPages(Pages pages) {
		this.pages = pages;
	}

	public int getCurrentPage() {
		return currentPage;
	}

	public void setCurrentPage(int currentPage) {
		this.currentPage = currentPage;
	}

	public SarcSupplier getSsup() {
		return ssup;
	}

	public void setSsup(SarcSupplier ssup) {
		this.ssup = ssup;
	}

	public int getIndex() {
		return index;
	}

	public void setIndex(int index) {
		this.index = index;
	}
}
